package object;


import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.Queue;

class Node {
    public String val;
    public Node left;
    public Node right;
    public Node(String val) {
        this.val = val;
        this.left = null;
        this.right = null;
    }
}
//这可以表示一棵树
class Tree {
    public Node root;
}
public class Test {
    //下面这个方法并不是创建二叉树的真证方法，这是模拟实现一个简单的二叉树
    //以后会学
    public static Node creatTree() {
        Node a = new Node("A");
        Node b = new Node("B");
        Node c = new Node("C");
        Node d = new Node("D");
        Node e = new Node("E");
        Node f = new Node("F");
        Node g = new Node("G");

        a.left = b;
        a.right = c;
        b.left = d;
        b.right = e;
        c.left = f;
        c.right = g;

        return a;
    }
    public static void prevOrder(Node root) {
        if(root == null) {
            return;
        }
        System.out.println(root.val + "");
        prevOrder(root.left);
        prevOrder(root.right);
    }
    public static void inOrder(Node root) {
        if(root == null) {
            return;
        }
        inOrder(root.left);
        System.out.println(root.val + "");
        inOrder(root.right);
    }
    public static void postOrder(Node root) {
        if(root == null) {
            return;
        }
        postOrder(root.left);
        postOrder(root.right);
        System.out.println(root.val + "");
    }
    public static void levelOrder(Node root) {
        if(root == null) {
            return;
        }
        Queue<Node> queue = new LinkedList<>();
        queue.offer(root);
        while (!queue.isEmpty()) {
            Node cur = queue.poll();
            System.out.println(cur.val + "");
            if(cur.left != null) {
                queue.offer(cur.left);
            }
            if(cur.right != null) {
                queue.offer(cur.right);
            }
        }
    }
    public static void main(String[] args) {
        //这也可以表示一棵树
        //Node root = new Node("A");
        //把tree实例化表示一棵树
        //Tree tree = new Tree();

        Node root = creatTree();
        //prevOrder(root);
        //inOrder(root);
        //postOrder(root);
        levelOrder(root);
    }
}
